using System;
using System.Collections.Generic;
using System.Text;
using GarageGames.Torque.T2D;
using GarageGames.Torque.Materials;
using Microsoft.Xna.Framework;

namespace Xyne.Templates.Ui.BattleRegion.Bars
{
    public class HealthBar : T2DStaticSprite
    {
        #region Private Vars
        private static HealthBar _template;

        private float health;
        private float maxHealth;
        private float fullHeight;

        private Vector2 origin;
        #endregion

        #region Properties
        public static HealthBar Template
        {
            get
            {
                if (_template == null)
                {
                    _template = new HealthBar();
                }
                return _template;
            }
        }

        public float Health
        {
            get
            {
                return health;
            }

            set
            {
                health = value;
                float newHeight = fullHeight * health / maxHealth;
                Size = new Vector2(Size.X, newHeight);
                Position = origin + new Vector2(0,(fullHeight - newHeight) / 2);
            }
        }

        public Vector2 Origin
        {
            get
            {
                return origin;
            }

            set
            {
                origin = value;
            }
        }

        public float MaxHealth
        {
            get
            {
                return maxHealth;
            }

            set
            {
                maxHealth = value;
            }
        }

        public float FullHeight
        {
            get
            {
                return fullHeight;
            }

            set
            {
                fullHeight = value;
            }
        }
        #endregion

        #region Constructor
        public HealthBar()
        {
            this.IsTemplate = true;

            SimpleMaterial tempMaterial = new SimpleMaterial();
            tempMaterial.TextureFilename = @"data\images\ui\battleregion\bars\playerhealth.png";

            Material = tempMaterial;

            Layer = Game.BarsLayer;

            Name = "HealthBarTemplate";

            Size = new Vector2(10, 100);

        }
        #endregion

        #region Methods
        #endregion
    }
}
